﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;

using CE.Mail;
using CE.Image;
using CE.User;
using CE.Database;
using CE.TravelInsurance;
using CE.Global;
using CE.Provider;
using CE.AreaCountry;


public partial class travel_insurance_results : System.Web.UI.Page
{
    private Int32 RowCount = 0;
    private string TripType = "S";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.IsSecureConnection)
            {
                string redirectUrl = Request.Url.ToString().Replace("https:", "http:");
                Response.Redirect(redirectUrl);
            }

            if (Request.UrlReferrer == null)
            {
                BackToSearchPage();
            }

            if (Session[General.TAId] != null)
            {
                inputPlanType.Value = Session["PlanType"].ToString();
                LoadSummary();
            }

            Session[General.TAResultId] = null;
            ResultsQuotesDataBind();
            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();


            if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Provider))
            {
                txtFullName.ReadOnly = false;
                txtMobileNo.IsReadOnly = false;
                txtEmail.ReadOnly = false;
            }
            else
            {

                if (Session[General.UserId] != null)
                {
                    if (Session[General.UserName] != null)
                    {
                        if (Session[General.UserName].ToString() != "")
                        {

                            General.UserTypeId =
                            txtFullName.Text = Session[General.UserName].ToString();
                            txtMobileNo.PhoneNo = Session[General.UserPhoneNo].ToString();
                            txtEmail.Text = Session[General.UserEmail].ToString();

                            txtFullName.ReadOnly = true;
                            txtMobileNo.IsReadOnly = true;
                            txtEmail.ReadOnly = true;
                        }
                    }
                    else if (Session[General.TAUserName] != null)
                    {
                        if (Session[General.TAUserName].ToString() != "")
                        {
                            txtFullName.Text = Session[General.TAUserName].ToString();
                            txtMobileNo.PhoneNo = Session[General.TAPhoneNo].ToString();
                            txtEmail.Text = Session[General.TAEmail].ToString();

                            txtFullName.ReadOnly = true;
                            txtMobileNo.IsReadOnly = true;
                            txtEmail.ReadOnly = true;
                        }
                    }
                }

                else
                {
                    txtFullName.ReadOnly = false;
                    txtMobileNo.IsReadOnly = false;
                    txtEmail.ReadOnly = false;
                }
            }
        }
    }

    private void BackToSearchPage()
    {
        if (Request.QueryString["pid"] != null)
        {
            if (Request.QueryString["pid"].ToString() != "")
            {
                Response.Redirect("~/travel-insurance/travel-quote.aspx?pid=" + Request.QueryString["pid"].ToString());
            }
            else
            {
                Response.Redirect("~/travel-insurance/");
            }
        }
        else
        {
            Response.Redirect("~/travel-insurance/");
        }
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        //Sakthi on 15 Feb 2011 Command
        //return _userviewdb.LogViewedHistory("TA", Request, "Travel Insurance results quotes one.");
        return _userviewdb.LogResultViewedHistory("TA", Request, "Travel Insurance results quotes one.");
    }

    private void LogUserSelectHistory(string CoverType, Int64 ResultId, Int64 CompanyId)
    {
        UserSelectHistoryDB _userselectdb = new UserSelectHistoryDB();
        if (CoverType.ToLower() == "ind")
        {
            _userselectdb.LogUserSelectHistory("TA", Request.Browser.Type, Request.UserHostAddress, "TAIND", ResultId, CompanyId);
        }
        else if (CoverType.ToLower() == "ins")
        {
            _userselectdb.LogUserSelectHistory("TA", Request.Browser.Type, Request.UserHostAddress, "TAINDSP", ResultId, CompanyId);
        }
        else
        {
            _userselectdb.LogUserSelectHistory("TA", Request.Browser.Type, Request.UserHostAddress, "TAFML", ResultId, CompanyId);
        }

    }

    protected void LoadSummary()
    {
        Int64 TAId = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {

            lblTripType.Text = GetCoverage(_taapplicantsearch.TripType.ToString());
            TripType = _taapplicantsearch.TripType.ToString();
            lblPolicy.Text = GetPolicy(_taapplicantsearch.PlanType.ToString());
            lblTravelDate.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
            lblTravellers.Text = (_taapplicantsearch.NoofChilds + _taapplicantsearch.NoofAdults).ToString();

            inputNoOfAdult.Value = _taapplicantsearch.NoofAdults.ToString();

            if (_taapplicantsearch.AreaID != 0)
                lblDestination.Text = GetAreaName(_taapplicantsearch.AreaID);
            else
                lblDestination.Text = GetCountryName(_taapplicantsearch.CountryID);

        }
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";

        if (covertype == "IND")
        {
            policy = "Individual";
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
        }
        else if (covertype == "FML")
        {
            policy = "Family";
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }

    protected void gvTravelResult_RowDatabound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Image imgCompanyLogo = (Image)e.Row.FindControl("imgCompanyLogo");
            Label lblInsurerName = (Label)e.Row.FindControl("lblInsurerName");
            Label lblTempId = (Label)e.Row.FindControl("lblTempId");

            lblTempId.Text = DataBinder.Eval(e.Row.DataItem, "TAInsID").ToString();
            string providercompanyid = DataBinder.Eval(e.Row.DataItem, "providercompanyid").ToString();
            string imageurl = "/images/public/logo/";

            string plan_name = DataBinder.Eval(e.Row.DataItem, "planname").ToString();
            lblInsurerName.Text = plan_name;
            if (providercompanyid == "23")
            {
                imageurl += "hsbc.png";
                //lblInsurerName.Text = "HSBC Insurance";
            }
            else if (providercompanyid == "24")
            {
                imageurl += "rsa.png";
                //lblInsurerName.Text = "RSA Insurance";
            }
            else if (providercompanyid == "29")
            {
                imageurl += "liberty.png";
                //lblInsurerName.Text = "Liberty Insurance";
            }
            else if (providercompanyid == "30")
            {
                imageurl += "etiqa.png";
                //lblInsurerName.Text = plan_name; // "Etiqa Insurance";
            }
            else if (providercompanyid == "31")
            {
                imageurl += "chartis.png";
                //lblInsurerName.Text = "Chartis Insurance";
            }
            else if (providercompanyid == "34")
            {
                imageurl += "chinataiping.png";
                //lblInsurerName.Text = "China Taiping Insurance";
            }
            else if (providercompanyid == "35")
            {
                imageurl += "eq.png";
                //lblInsurerName.Text = "EQ Insurance";
            }
            else if (providercompanyid == "36")
            {
                imageurl += "ace.png";
                //lblInsurerName.Text = "ACE Insurance";
            }
            else if (providercompanyid == "37")
            {
                imageurl += "1cover.png";
                //lblInsurerName.Text = "1Cover Insurance";
            }
            else if (providercompanyid == "38")
            {
                imageurl += "directasia.png";
                //lblInsurerName.Text = "DirectAsia Insurance";
            }

            imgCompanyLogo.ImageUrl = imageurl;

            Button btnLearnMore = (Button)e.Row.FindControl("btnLearnMore");
            //btnLearnMore.CommandArgument = e.Row.RowIndex.ToString();

            Int64 _resultId = Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "TAInsID").ToString());
            string _AnnualPremium = DataBinder.Eval(e.Row.DataItem, "AnnualPremium").ToString();
            Label lblPremium = (Label)e.Row.FindControl("lblPremium");
            lblPremium.Text = string.Format("${0:c}", _AnnualPremium);

            //Ace 20% discount DESC      

            //if (providercompanyid == "36" && TripType == "S")
            // {
            Int32 promodiscount = GetPromoDiscount(providercompanyid);

            if (promodiscount > 0)
            {

                //if (providercompanyid == "23" && TripType == "A")
                //{
                //    Image imgPromo = (Image)e.Row.FindControl("imgPromo");
                //    imgPromo.ImageUrl = "~/images/promo/bag-ico.gif";
                //    imgPromo.Visible = true;
                //    imgPromo.ImageAlign = ImageAlign.AbsMiddle;
                //}
                //else 
                //if (providercompanyid == "29")
                //{
                //    promodiscount = 20;                
                //}

                //if ((providercompanyid == "29" && TripType == "S") || providercompanyid != "29")
                //{
                //    lblPremium.Text = string.Format("{0:c}", Convert.ToSingle(_AnnualPremium));
                //    lblPremium.Text += " <s>" + string.Format("{0:c}", Convert.ToSingle(_AnnualPremium) / (Convert.ToDouble(100 - promodiscount) / 100)) + "</s>";
                //}

                lblPremium.Text = string.Format("{0:c}", Convert.ToSingle(_AnnualPremium));
                lblPremium.Text += " <s>" + string.Format("{0:c}", Convert.ToSingle(_AnnualPremium) / (Convert.ToDouble(100 - promodiscount) / 100)) + "</s>";

            }

            //}


            Int64 UserId = 0;
            if (Session[General.UserId] != null)
            {
                UserId = Convert.ToInt64(Session[General.UserId].ToString());
            }
            else if (Session[General.TAPersonnelId] != null)
            {
                UserId = Convert.ToInt64(Session[General.TAPersonnelId].ToString());
            }
            Int64 TAId = Convert.ToInt64(Session[General.TAId].ToString());

            string PlanName = DataBinder.Eval(e.Row.DataItem, "PlanName").ToString();

            btnLearnMore.OnClientClick = "javascript:void(0);ShowPopupLearnMore('" + providercompanyid + "', '" + imageurl + "', '" + _resultId + "', '" + _AnnualPremium + "', '" + UserId + "','" + TAId + "', '" + PlanName + "');return false;";

        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Text = "";
            e.Row.Cells[1].Text = "";
            e.Row.Cells[2].Text = "";
            e.Row.Cells[3].Text = "";
            e.Row.Cells[4].Text = "";
        }

    }

    private bool SaveSelectedInsurance(Int64 TAAppSeaId, Int64 TAInsId, Int64 ProviderCompanyId, float AnnualPremium, Int64 RefCEUserId, bool Status)
    {
        Int64 _result = 0;
        TASelectedInsurance _taselectedinsurance = new TASelectedInsurance();
        TASelectedInsuranceDB _taselectedinsurancedb = new TASelectedInsuranceDB();
        _taselectedinsurance.TAAppSeaId = TAAppSeaId;
        _taselectedinsurance.TAInsId = TAInsId;
        _taselectedinsurance.ProviderCompanyId = ProviderCompanyId;
        _taselectedinsurance.AnnualPremium = AnnualPremium;
        _taselectedinsurance.RefCEUserId = RefCEUserId;
        _taselectedinsurance.Status = Status;
        _result = _taselectedinsurancedb.Insert(_taselectedinsurance);
        return _result > 0;
    }

    private bool SaveMailStatus(Int64 TAAppSeaId, Int64 TAInsId, Int64 ProviderCompanyId, bool Status)
    {
        Int64 _result = 0;
        TASelectedInsurance _taselectedinsurance = new TASelectedInsurance();
        TASelectedInsuranceDB _taselectedinsurancedb = new TASelectedInsuranceDB();
        _taselectedinsurance.TAAppSeaId = TAAppSeaId;
        _taselectedinsurance.TAInsId = TAInsId;
        _taselectedinsurance.ProviderCompanyId = ProviderCompanyId;
        _taselectedinsurance.Status = Status;
        _result = _taselectedinsurancedb.InsertMailStatus(_taselectedinsurance);
        return _result > 0;
    }

    private string Get1CoverTravelDuration(Int32 Duration)
    {
        string _Duration = "0";
        if (Duration >= 1 && Duration <= 3)
        {
            _Duration = "1";
        }
        else if (Duration >= 4 && Duration <= 6)
        {
            _Duration = "2";
        }
        else if (Duration >= 7 && Duration <= 10)
        {
            _Duration = "3";
        }
        else if (Duration >= 11 && Duration <= 14)
        {
            _Duration = "4";
        }
        else if (Duration >= 15 && Duration <= 18)
        {
            _Duration = "5";
        }
        else if (Duration >= 19 && Duration <= 22)
        {
            _Duration = "6";
        }
        else if (Duration >= 23 && Duration <= 27)
        {
            _Duration = "7";
        }
        else if (Duration >= 28 && Duration <= 31)
        {
            _Duration = "8";
        }
        else if (Duration >= 32 && Duration <= 38)
        {
            _Duration = "9";
        }
        else if (Duration >= 39 && Duration <= 45)
        {
            _Duration = "10";
        }
        else if (Duration >= 46 && Duration <= 52)
        {
            _Duration = "11";
        }
        else if (Duration >= 53 && Duration <= 59)
        {
            _Duration = "12";
        }
        else if (Duration >= 60 && Duration <= 66)
        {
            _Duration = "13";
        }
        else if (Duration >= 67 && Duration <= 73)
        {
            _Duration = "14";
        }
        else if (Duration >= 74 && Duration <= 80)
        {
            _Duration = "15";
        }
        else if (Duration >= 81 && Duration <= 87)
        {
            _Duration = "16";
        }
        else if (Duration >= 88 && Duration <= 94)
        {
            _Duration = "17";
        }
        else if (Duration >= 95 && Duration <= 101)
        {
            _Duration = "18";
        }
        else if (Duration >= 102 && Duration <= 108)
        {
            _Duration = "19";
        }
        else if (Duration >= 109 && Duration <= 115)
        {
            _Duration = "20";
        }
        else if (Duration >= 116 && Duration <= 122)
        {
            _Duration = "21";
        }
        else if (Duration >= 123 && Duration <= 129)
        {
            _Duration = "22";
        }
        else if (Duration >= 130 && Duration <= 136)
        {
            _Duration = "23";
        }
        else if (Duration >= 137 && Duration <= 143)
        {
            _Duration = "24";
        }
        else if (Duration >= 144 && Duration <= 150)
        {
            _Duration = "25";
        }
        else if (Duration >= 151 && Duration <= 157)
        {
            _Duration = "26";
        }
        else if (Duration >= 158 && Duration <= 164)
        {
            _Duration = "27";
        }
        else if (Duration >= 165 && Duration <= 171)
        {
            _Duration = "28";
        }
        else if (Duration >= 172 && Duration <= 178)
        {
            _Duration = "29";
        }
        else if (Duration >= 179 && Duration <= 180)
        {
            _Duration = "30";
        }
        return _Duration;
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private TableCell[] CreateCells()
    {

        TableCell[] cells = new TableCell[1];
        TableCell cell;
        Label lbl;

        //The order item column
        cell = new TableCell();
        cell.Width = 220;
        cell.Height = 50;
        lbl = new Label();
        lbl.Text = "Buy Now!";
        cell.Controls.Add(lbl);
        cells[0] = cell;

        //The price column
        //cell = new TableCell();
        //lbl = new Label();
        //lbl.Font.Bold = true;
        //lbl.Text = "test";
        //cell.HorizontalAlign = HorizontalAlign.Right;
        //cell.Controls.Add(lbl);
        //cells[1] = cell;

        return cells;
    }

    private void GetTempResultTable()
    {
        string CoverType = "";
        Int32 Duration = 0;
        string CoverageLevel = "";
        string Trip = "";
        Int64 AreaId = 0;
        Int64 CountryId = 0;
        Int32 AdultAge = 0;
        Int32 ChildAge = 0;
        Int64 TAId = 0;
        Int32 NoOfAdults = 0;
        Int32 NoOfChilds = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null && Session[General.TAId].ToString() != "")
            TAId = Convert.ToInt64(Session[General.TAId].ToString());
        else
        {
            //Response.Redirect("travel-quote.aspx");
            BackToSearchPage();            
        }

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {
            //Response.Write("<script>window.alert('ok ')</script>");
            CoverType = _taapplicantsearch.PlanType;
            Duration = _taapplicantsearch.Duration;
            AreaId = _taapplicantsearch.AreaID;
            CountryId = _taapplicantsearch.CountryID;
            AdultAge = _taapplicantsearch.AdultAge;
            ChildAge = _taapplicantsearch.ChildAge;
            CoverageLevel = _taapplicantsearch.CoverageLevel;
            Trip = _taapplicantsearch.TripType;
            NoOfAdults = _taapplicantsearch.NoofAdults;
            NoOfChilds = _taapplicantsearch.NoofChilds;
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable();


            TAQuoteResultDB _taquoteresultdb = new TAQuoteResultDB();

            //DateTime dt = CE.Global.General.GetUTCDateTime();
            //Int64 iDate = Convert.ToInt64(String.Format("{0:yMMddhhmm}", dt));

            //Int64 PromoStart = Convert.ToInt64(CE.Configuration.MyConfigurationManager.GetAppSettingValue("TravelACEPromoStart"));
            //Int64 PromoEnd = Convert.ToInt64(CE.Configuration.MyConfigurationManager.GetAppSettingValue("TravelACEPromoEnd"));

            ////Cheryl 18 Aug 2011 - ACE Promo
            //if (iDate >= PromoStart && iDate < PromoEnd)  //Promo Period  
            //{
            //    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
            //     Convert.ToInt32(CE.Global.CEUserType.Provider) && Session[CE.Global.General.ProviderCompanyId] != null)
            //    {
            //        _dtResult = _taquoteresultdb.GetTAQuoteResultDisplayByProviderWithPromo(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), NoOfAdults, NoOfChilds, TAId);
            //    }
            //    else
            //    {
            //        _dtResult = _taquoteresultdb.GetTAQuoteResultDisplayWithPromo(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Trip, NoOfAdults, NoOfChilds, TAId);
            //    }
            //}
            //else
            //{
            if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
             Convert.ToInt32(CE.Global.CEUserType.Provider) && Session[CE.Global.General.ProviderCompanyId] != null)
            {
                //Sakthi on 30 Dec 2010
                //_dtResult = _taquoteresultdb.GetTAQuoteResultDisplayByProvider(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), NoOfAdults);
                _dtResult = _taquoteresultdb.GetTAQuoteResultDisplayByProvider(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), NoOfAdults, NoOfChilds, TAId);

            }
            else if (_taapplicantsearch.Ninfo3 != 0)
            {
                //with Promo per Provider
                _dtResult = _taquoteresultdb.GetTAQuoteResultDisplayByProviderWithPromo(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, _taapplicantsearch.Ninfo3, NoOfAdults, NoOfChilds, TAId);
            }
            else
            {

                //Sakthi on 30 Dec 2010
                //_dtResult = _taquoteresultdb.GetTAQuoteResultDisplay(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Trip, NoOfAdults);
                _dtResult = _taquoteresultdb.GetTAQuoteResultDisplay(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Trip, NoOfAdults, NoOfChilds, TAId);

            }
            // }

            RowCount = _dtResult.Rows.Count;


            DataView dv = new DataView(_dtResult);
            string strSortExpress = "AnnualPremium ASC";

            dv.Sort = strSortExpress;
            Cache["TAResultsQuotes" + Session[General.TAId].ToString()] = dv.ToTable();

            //Cache["TAResultsQuotes"] = _dtResult;
        }
        else
        {
            BackToSearchPage();
          
        }

    }

    private string GetCovertype(string covertype)
    {
        string coverparam = "";
        if (covertype == "IND")
            coverparam = "Individual";
        else if (covertype == "INS")
            coverparam = "IndividualSpouse";
        else if (covertype == "FML")
            coverparam = "Family";
        else if (covertype == "INC")
            coverparam = "IndividualChild";

        return coverparam;
    }

    private void ResultsQuotesDataBind()
    {
        if (Session[General.TAId] == null)
        {
            BackToSearchPage();
            
        }

        //Sakthi on 30 Dec 2010 -- Start
        if (Request.UrlReferrer != null)
        {
            if (Request.UrlReferrer.ToString().ToLower().IndexOf("viewresulthistory.aspx") > 0 || Request.UrlReferrer.ToString().ToLower().IndexOf("travel-quote.aspx") > 0)
            {
                GetTempResultTable();
            }
        }
        //Sakthi on 30 Dec 2010 -- End
        if (Cache["TAResultsQuotes" + Session[General.TAId].ToString()] == null)
            GetTempResultTable();

        DataView dv = new DataView((DataTable)Cache["TAResultsQuotes" + Session[General.TAId].ToString()]);

        if (dv.Count > 0)
        {
            RowCount = dv.Count;

            if (Request.UrlReferrer != null)
            {
                if (Request.UrlReferrer.ToString().ToLower().IndexOf("viewresulthistory.aspx") > 0 || Request.UrlReferrer.ToString().ToLower().IndexOf("travel-quote.aspx") > 0)
                {
                    Session["DefaultSort"] = null;
                    Session["SortExp"] = null;

                    dv.Sort = "AnnualPremium ASC";

                    Cache["TAResultsQuotes" + Session[General.TAId].ToString()] = dv.ToTable();
                }
            }


            gvTravelResult.DataSource = dv;
            gvTravelResult.DataBind();

            imgbtnCompare.Visible = true;
            imgbtnCompare2.Visible = true;
            imgdown.Visible = true;
            imgup.Visible = true;

        }
        else
        {
            gvTravelResult.DataSource = dv;
            gvTravelResult.DataBind();

            imgbtnCompare.Visible = false;
            imgbtnCompare2.Visible = false;
            imgdown.Visible = false;
            imgup.Visible = false;

            gvTravelResult.EmptyDataText = "more than 6 months";
        }

    }

    public void OpeNewWindow(string URL)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script>");
        sb.Append("window.open('" + URL + "', '');");
        sb.Append("</scri");
        sb.Append("pt>");
        Page.RegisterStartupScript("HSBC - CompareXpress", sb.ToString());
    }

    protected void ibtnBack_Click(object sender, EventArgs e)
    {
        Session["DefaultSort"] = null;
        Session["SortExp"] = null;

        if (Session[General.TAId] != null)
        {
            Cache.Remove("TAResultsQuotes" + Session[General.TAId].ToString());
        }
        //General.ClearAllSession(this.Page, "ALL");
        BackToSearchPage();
    }

    private void ProposalNotification(Int64 TAAppSeaId, Int64 ProviderCompanyId)
    {
        string _date, _time, _refNo, _QuoteDate, _selectedDate, _startDate, _endDate, _providerName, _customerName, _customerEmail, _customerContactNo;
        string _premium, _planType, _planName, _destination, _tripType, _InsuranceName, _CXEmail, _CXCCEmail, _CXBCCEmail, _userId, _NoofAdults, _NoofChilds;

        _date = ""; _time = ""; _refNo = ""; _QuoteDate = ""; _selectedDate = ""; _startDate = ""; _endDate = ""; _providerName = ""; _customerName = "";
        _customerEmail = ""; _customerContactNo = ""; _premium = ""; _planType = ""; _planName = ""; _tripType = ""; _destination = ""; _CXEmail = "";
        _CXCCEmail = ""; _CXBCCEmail = ""; _userId = "0"; _NoofAdults = "0"; _NoofChilds = "0";

        _InsuranceName = "Travel Insurance";
        _CXEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CX_TO");
        _CXCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CX_CC");
        _CXBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CX_BCC");

        if (Session[General.UserId] != null && Session[General.UserId].ToString() != "0")
        {
            _userId = Session[General.UserId].ToString();
        }
        else if (Session[General.TAPersonnelId] != null)
        {
            _userId = Session[General.TAPersonnelId].ToString();
        }
        MyDatabase _db = new MyDatabase();
        DataTable _dtResult = new DataTable();
        string _spName = "[sprocTIProposalFromCXSelectItembyProvider]";
        SortedList _sPara = new SortedList();
        _sPara.Add("@TAAppSeaId", TAAppSeaId);
        _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
        _sPara.Add("@RefCEUserId", Convert.ToInt64(_userId));
        _dtResult = _db.GetDataTableBySP(_spName, _sPara);

        if ((_dtResult != null) && (_dtResult.Rows.Count > 0))
        {
            _date = _dtResult.Rows[0]["Date"].ToString();
            _time = _dtResult.Rows[0]["Time"].ToString();
            _refNo = _dtResult.Rows[0]["TAAppSeaId"].ToString();
            _QuoteDate = Convert.ToDateTime(_dtResult.Rows[0]["QuoteDate"].ToString()).ToString("dd/MMM/yyyy");
            _selectedDate = Convert.ToDateTime(_dtResult.Rows[0]["SelectedDate"].ToString()).ToString("dd/MMM/yyyy hh:mm");
            _startDate = Convert.ToDateTime(_dtResult.Rows[0]["StartDate"].ToString()).ToString("dd/MMM/yyyy");
            _endDate = Convert.ToDateTime(_dtResult.Rows[0]["EndDate"].ToString()).ToString("dd/MMM/yyyy");
            _providerName = _dtResult.Rows[0]["CompanyName"].ToString();

            //Sakthi on 15 Feb 2011 -- Start
            //if (Session[General.UserId] != null && Session[General.UserId].ToString() != "0")
            //{
            //    _customerName = _dtResult.Rows[0]["CustomerName"].ToString();
            //    _customerEmail = _dtResult.Rows[0]["Email"].ToString();
            //    _customerContactNo = _dtResult.Rows[0]["Mobile"].ToString();
            //}
            //else if (Session[General.TAPersonnelId] != null)
            //{
            //    _customerName = _dtResult.Rows[0]["CustomerName"].ToString();
            //    _customerEmail = _dtResult.Rows[0]["Email"].ToString();
            //    _customerContactNo = _dtResult.Rows[0]["Mobile"].ToString();
            //}
            _customerName = _dtResult.Rows[0]["CustomerName"].ToString();
            _customerEmail = _dtResult.Rows[0]["Email"].ToString();
            _customerContactNo = _dtResult.Rows[0]["Mobile"].ToString();
            //Sakthi on 15 Feb 2011 -- End

            _premium = _dtResult.Rows[0]["AnnualPremium"].ToString();
            _planType = _dtResult.Rows[0]["PlanType"].ToString();
            _planName = _dtResult.Rows[0]["PlanName"].ToString();
            _tripType = _dtResult.Rows[0]["TripType"].ToString();
            _destination = _dtResult.Rows[0]["Destination"].ToString();
            _NoofAdults = _dtResult.Rows[0]["NoofAdults"].ToString();
            _NoofChilds = _dtResult.Rows[0]["NoofChilds"].ToString();
            MyMailManager.SendTIProposalNotification(_providerName, _InsuranceName, _refNo, _date, _time, _customerName, _customerEmail, _customerContactNo,
                _planName, _planType, _tripType, _destination, _premium, _startDate, _endDate, _QuoteDate, _selectedDate, _CXEmail, _CXCCEmail, _CXBCCEmail,
                _userId, _NoofAdults, _NoofChilds);
        }

    }

    private bool SendMailToUser()
    {

        string userfirstname = txtFullName.Text;

        bool _retVal = false;

        string _emailTo = txtEmail.Text;
        string _customername = userfirstname;
        string _emailSubject = "Your Travel Insurance Quotes on CompareXpress";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background:white;margin:0; padding:0; color:#4c4c4c; font-family:Arial, Helvetica, sans-serif; font-size:0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center>";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' style='padding:20px;' width='600'>";
        _mailBody += "<tr><td width='360'><a href='http://www.comparexpress.com/travel-insurance/' target='_blank'><img src='" + _currentDomainUrl + "/images/email/header_quote.png' width='596' height='187' alt='CompareXpress' border='0' /></a></td></tr>";
        //_mailBody += "<tr><td style='padding-left:45px; padding-right:45px;'><strong>Dear " + Session[General.UserName].ToString() + ",</strong><br/><br/>";
        _mailBody += "<tr><td style='padding-left:45px; padding-right:45px;'><strong>Dear " + userfirstname + ",</strong><br/><br/>";
        _mailBody += "Thank you for using CompareXpress Travel Insurance Comparison Engine:<br/><br/>";
        _mailBody += "Please find below a copy of your requested quote.<br/><br/>";

        DataView dvResults = new DataView((DataTable)Cache["TAResultsQuotes" + Session[General.TAId].ToString()]);

        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='546px' class='table_details'>";

        string strTAId = inputResultId.Value;
        dvResults.RowFilter = " TAInsID in (" + strTAId + ")";

        DataTable dtResults = dvResults.ToTable();


        if (dtResults.Rows.Count > 0)
        {
            string _providercompanyid = dtResults.Rows[0]["providercompanyid"].ToString();
            string insurername = dtResults.Rows[0]["InsurerName"].ToString();
            //logo
            string logourl = "/images/public/logo/";
            if (_providercompanyid == "23")
            {
                logourl += "hsbc.png";
                insurername = "HSBC Insurance";
            }
            if (_providercompanyid == "24")
            {
                logourl += "rsa.png";
                insurername = "RSA Insurance";
            }
            else if (_providercompanyid == "29")
            {
                logourl += "liberty.png";
                insurername = "Liberty Insurance";
            }
            else if (_providercompanyid == "30")
            {
                logourl += "etiqa.png";
                insurername = "Etiqa Insurance";
            }
            else if (_providercompanyid == "31")
            {
                logourl += "chartis.png";
                insurername = "Chartis Insurance";
            }
            else if (_providercompanyid == "34")
            {
                logourl += "chinataiping.png";
                insurername = "China Taiping Insurance";
            }
            else if (_providercompanyid == "35")
            {
                logourl += "eq.png";
                insurername = "EQ Insurance";
            }
            else if (_providercompanyid == "36")
            {
                logourl += "ace.png";
                insurername = "ACE Insurance";
            }
            else if (_providercompanyid == "37")
            {
                logourl += "1cover.png";
                insurername = "1Cover Insurance";
            }
            else if (_providercompanyid == "38")
            {
                logourl += "directasia.png";
                insurername = "DirectAsia Insurance";
            }
            _mailBody += "<tr>";
            _mailBody += "<td width='45%'></td>";
            _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
            _mailBody += "</tr>";

            //insurer name
            _mailBody += "<tr>";
            _mailBody += "<td><strong>Insurer</strong></td>";
            _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + insurername + "</strong></td>";
            _mailBody += "</tr>";

            //premium
            string premium = "";
            if (_providercompanyid == "36")
            {
                double _discounted = Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()) * 0.9;
                premium = "<small>" + String.Format("${0:0,0.00}", _discounted) + "</small>";
                premium += "  <s>" + String.Format("${0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString())) + "</s>";
            }
            else
            {
                premium = String.Format("${0:0,0.00}", Convert.ToSingle(dtResults.Rows[0]["annualpremium"].ToString()));
            }

            _mailBody += "<tr>";
            _mailBody += "<td align='left' style='background:#d5d5d5' ><strong>Price</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5; color:black; font-size:20px;'><strong>" + premium + "</strong></td>";
            _mailBody += "</tr>";

            if (_providercompanyid == "34") //pdf only for all benefits
            {
                //PDF benefit               
                string benefitsurl = _currentDomainUrl + "/policy_docs/ChinaTaiping/Coverage.pdf";
                string viewbenefitspdf = "<a href='" + benefitsurl + "' ><img src='" + _currentDomainUrl + "/images/icon/pdf.png'  alt='policy wordings' width='23' alt='NA' border='0'/></a>";

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Benefits</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + viewbenefitspdf + "</td>";
                _mailBody += "</tr>";
            }
            else
            {
                //Personal Accident adult
                string PAadult = "";
                float _fPAadult = 0;
                if (dtResults.Rows[0]["DTPD_LessYr70"].ToString() != "")
                {
                    _fPAadult = Convert.ToSingle(dtResults.Rows[0]["DTPD_LessYr70"].ToString());
                }

                if (_fPAadult > 0.0f)
                {
                    string _PAadultAmount = String.Format("${0:0,0}", _fPAadult);
                    PAadult = _PAadultAmount;
                }
                else
                {
                    PAadult = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Personal Accident </strong>(adult)</td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + PAadult + "</td>";
                _mailBody += "</tr>";

                //Personal Accident >70
                string PA70 = "";
                float _fPA70 = 0;
                if (dtResults.Rows[0]["DTPD_AboveYr70"].ToString() != "")
                {
                    _fPA70 = Convert.ToSingle(dtResults.Rows[0]["DTPD_AboveYr70"].ToString());
                }

                if (_fPA70 > 0.0f)
                {
                    string _PA70 = String.Format("${0:0,0}", _fPA70);
                    PA70 = _PA70;
                }
                else
                {
                    PA70 = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Personal Accident</strong> (> 70)</td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + PA70 + "</td>";
                _mailBody += "</tr>";

                //Double Indemnity adult
                string DIadult = "";
                float _fDIadult = 0;
                if (dtResults.Rows[0]["DIPC_LessYr70"].ToString() != "")
                {
                    _fDIadult = Convert.ToSingle(dtResults.Rows[0]["DIPC_LessYr70"].ToString());
                }

                if (_fDIadult > 0.0f)
                {
                    string _DIadult = String.Format("${0:0,0}", _fDIadult);
                    DIadult = _DIadult;
                }
                else
                {
                    DIadult = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Double Indemnity </strong>(adult)</td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + DIadult + "</td>";
                _mailBody += "</tr>";


                //Double Indemnity >70
                string DI70 = "";
                float _fDI70 = 0;
                if (dtResults.Rows[0]["DIPC_AboveYr70"].ToString() != "")
                {
                    _fDI70 = Convert.ToSingle(dtResults.Rows[0]["DIPC_AboveYr70"].ToString());
                }

                if (_fDI70 > 0.0f)
                {
                    string _DI70 = String.Format("${0:0,0}", _fDI70);
                    DI70 = _DI70;
                }
                else
                {
                    DI70 = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Double Indemnity </strong>(> 70)</td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + DI70 + "</td>";
                _mailBody += "</tr>";


                //MEd Expenses adult
                string MedExpenseAdult = "";
                float _fMedExpAdult = 0;
                if (dtResults.Rows[0]["MedExp_LessYr70"].ToString() != "")
                {
                    _fMedExpAdult = Convert.ToSingle(dtResults.Rows[0]["MedExp_LessYr70"].ToString());
                }

                if (_fMedExpAdult > 0.0f)
                {
                    string _MedExpAdult = String.Format("${0:0,0}", _fMedExpAdult);
                    MedExpenseAdult = _MedExpAdult;

                    if (_providercompanyid == "38")
                    {
                        MedExpenseAdult += "<br/>TCM: $300";
                    }
                    else if (_providercompanyid == "38")
                    {
                        MedExpenseAdult += "<br/>TCM: $750";
                    }
                }
                else
                {
                    MedExpenseAdult = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Medical Expenses </strong>(adult)</td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + MedExpenseAdult + "</td>";
                _mailBody += "</tr>";

                //MEd Expenses > 70
                string MedExpense70 = "";
                float _fMedExp70 = 0;
                if (dtResults.Rows[0]["MedExp_AboveYr70"].ToString() != "")
                {
                    _fMedExp70 = Convert.ToSingle(dtResults.Rows[0]["MedExp_AboveYr70"].ToString());
                }

                if (_fMedExp70 > 0.0f)
                {
                    string _MedExp70 = String.Format("${0:0,0}", _fMedExp70);
                    MedExpense70 = _MedExp70;

                    if (_providercompanyid == "38")
                    {
                        MedExpense70 += "<br/>TCM: $300";
                    }
                    else if (_providercompanyid == "36")
                    {
                        MedExpense70 += "<br/>TCM: $750";
                    }
                }
                else
                {
                    MedExpense70 = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Medical Expenses </strong>(> 70)</td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + MedExpense70 + "</td>";
                _mailBody += "</tr>";


                //Emergency Med Evac
                string EmergMedEvac = "";
                float _fEmergMedEvac = 0;
                if (dtResults.Rows[0]["EmMedEval"].ToString() != "")
                {
                    _fEmergMedEvac = Convert.ToSingle(dtResults.Rows[0]["EmMedEval"].ToString());
                }

                if (_fEmergMedEvac > 0.0f)
                {
                    string _EmergMedEvac = String.Format("${0:0,0}", _fEmergMedEvac);
                    EmergMedEvac = _EmergMedEvac;

                    if (_providercompanyid == "38")
                    {
                        EmergMedEvac += "<br/>(combined cover with Repatriation & Funeral Expense)";
                    }
                }
                else
                {
                    EmergMedEvac = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Emergency Medical Evacuation </strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + EmergMedEvac + "</td>";
                _mailBody += "</tr>";

                //Repatriation & Funeral Expenses
                string Repatriation = "";
                float _fRepatriation = 0;
                if (dtResults.Rows[0]["BCR"].ToString() != "")
                {
                    _fRepatriation = Convert.ToSingle(dtResults.Rows[0]["BCR"].ToString());
                }
                if (dtResults.Rows[0]["Info5"].ToString() == "True")
                {
                    Repatriation = "<font color=Red>*as charged</font>";

                    if (_providercompanyid == "36")
                    {
                        Repatriation = "<font color=Red>Unlimited</font>";
                    }
                }
                else
                {
                    if (_fRepatriation > 0.0f)
                    {
                        string _Repatriation = String.Format("${0:0,0}", _fRepatriation);
                        Repatriation = _Repatriation;

                        if (_providercompanyid == "38")
                        {
                            Repatriation += "<br/>(combined cover with Emergency Medical Evacuation)";
                        }
                    }
                    else
                    {
                        Repatriation = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                    }
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Repatriation & Funeral Expenses</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + Repatriation + "</td>";
                _mailBody += "</tr>";


                //Hospital Income
                string HospitalIncome = "";
                float _fHospitalIncome = 0;
                if (dtResults.Rows[0]["HospIncome"].ToString() != "")
                {
                    _fHospitalIncome = Convert.ToSingle(dtResults.Rows[0]["HospIncome"].ToString());
                }

                if (_fHospitalIncome > 0.0f)
                {
                    string _HospitalIncome = String.Format("${0:0,0}", _fHospitalIncome);
                    HospitalIncome = _HospitalIncome + "/day <br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo4"].ToString()));

                }
                else
                {
                    HospitalIncome = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Hospital Income</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + HospitalIncome + "</td>";
                _mailBody += "</tr>";

                //Pregnancy
                string Pregnancy = "";
                float _fPregnancy = 0;
                if (dtResults.Rows[0]["NInfo3"].ToString() != "")
                {
                    _fPregnancy = Convert.ToSingle(dtResults.Rows[0]["NInfo3"].ToString());
                }

                if (_fPregnancy > 0.0f)
                {
                    string _Pregnancy = String.Format("${0:0,0}", _fPregnancy);
                    Pregnancy = _Pregnancy;

                    if (_providercompanyid == "38")
                    {
                        Pregnancy = "Covered under Medical Expenses (adult)";
                    }
                }
                else
                {
                    Pregnancy = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Pregnancy-Related Illness </strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + Pregnancy + "</td>";
                _mailBody += "</tr>";


                //Overseas Compa Visit
                string OverseasCompVisit = "";
                float _fOverseasCompVisit = 0;
                if (dtResults.Rows[0]["CompassVisit"].ToString() != "")
                {
                    _fOverseasCompVisit = Convert.ToSingle(dtResults.Rows[0]["CompassVisit"].ToString());
                }

                if (_fOverseasCompVisit > 0.0f)
                {
                    string _OverseasCompVisit = String.Format("${0:0,0}", _fOverseasCompVisit);
                    OverseasCompVisit = _OverseasCompVisit;

                }
                else
                {
                    OverseasCompVisit = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Overseas Compassionate Visit</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + OverseasCompVisit + "</td>";
                _mailBody += "</tr>";


                //Child Guard
                string ChildGuard = "";
                float _fChildGuard = 0;
                if (dtResults.Rows[0]["ChildCare"].ToString() != "")
                {
                    _fChildGuard = Convert.ToSingle(dtResults.Rows[0]["ChildCare"].ToString());
                }

                if (_fChildGuard > 0.0f)
                {
                    string _ChildGuard = String.Format("${0:0,0}", _fOverseasCompVisit);
                    ChildGuard = _ChildGuard;

                }
                else
                {
                    ChildGuard = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Child Guard</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + ChildGuard + "</td>";
                _mailBody += "</tr>";


                //Personal Liablity
                string PersonalLiability = "";
                float _fPersonalLiability = 0;
                if (dtResults.Rows[0]["PersonalLiability"].ToString() != "")
                {
                    _fPersonalLiability = Convert.ToSingle(dtResults.Rows[0]["PersonalLiability"].ToString());
                }

                if (_fPersonalLiability > 0.0f)
                {
                    string _PersonalLiability = String.Format("${0:0,0}", _fPersonalLiability);
                    PersonalLiability = _PersonalLiability;

                }
                else
                {
                    PersonalLiability = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Personal Liability</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + PersonalLiability + "</td>";
                _mailBody += "</tr>";


                //Loss Baggage & Personal Effects
                string LossBaggage = "";
                float _fLossBaggage = 0;
                if (dtResults.Rows[0]["BagPerEffect"].ToString() != "")
                {
                    _fLossBaggage = Convert.ToSingle(dtResults.Rows[0]["BagPerEffect"].ToString());
                }

                if (_fLossBaggage > 0.0f)
                {
                    string _LossBaggage = String.Format("${0:0,0}", _fLossBaggage);
                    LossBaggage = _LossBaggage;

                    if (_providercompanyid == "38")
                    {
                        LossBaggage += "<br/>($500 per article/laptop/mobile phone or PDA)";
                    }

                }
                else
                {
                    LossBaggage = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Loss Baggage & Personal Effects</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + LossBaggage + "</td>";
                _mailBody += "</tr>";

                //OverseasBaggage
                string OverseasBaggage = "";
                float _fOverseasBaggage = 0;
                if (dtResults.Rows[0]["BagDelay"].ToString() != "")
                {
                    _fOverseasBaggage = Convert.ToSingle(dtResults.Rows[0]["BagDelay"].ToString());
                }

                if (_fOverseasBaggage > 0.0f)
                {
                    string _OverseasBaggage = String.Format("${0:0,0}", _fOverseasBaggage) + "/" + dtResults.Rows[0]["Ninfo5"].ToString() + "-hour delay";
                    _OverseasBaggage += "<br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo6"].ToString()));

                    OverseasBaggage = _OverseasBaggage;

                    if (_providercompanyid == "38")
                    {
                        OverseasBaggage = String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo6"].ToString()));
                    }

                }
                else
                {
                    OverseasBaggage = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Overseas Baggage Delay</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + OverseasBaggage + "</td>";
                _mailBody += "</tr>";


                //Trip Cancellation
                string TripCancellation = "";
                float _fTripCancellation = 0;
                if (dtResults.Rows[0]["DepositTripCancel"].ToString() != "")
                {
                    _fTripCancellation = Convert.ToSingle(dtResults.Rows[0]["DepositTripCancel"].ToString());
                }

                if (_fTripCancellation > 0.0f)
                {
                    string _TripCancellation = String.Format("${0:0,0}", _fTripCancellation);
                    TripCancellation = _TripCancellation;

                }
                else
                {
                    TripCancellation = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Trip Cancellation</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + TripCancellation + "</td>";
                _mailBody += "</tr>";


                //Trip Curtailment
                string TripCurtailment = "";
                float _fTripCurtailment = 0;
                if (dtResults.Rows[0]["Curtailment"].ToString() != "")
                {
                    _fTripCurtailment = Convert.ToSingle(dtResults.Rows[0]["Curtailment"].ToString());
                }

                if (_fTripCurtailment > 0.0f)
                {
                    string _TripCurtailment = String.Format("${0:0,0}", _fTripCurtailment);
                    TripCurtailment = _TripCurtailment;

                    if (_providercompanyid == "38")
                    {
                        TripCurtailment = TripCancellation;
                    }

                }
                else
                {
                    TripCurtailment = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Trip Curtailment</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + TripCurtailment + "</td>";
                _mailBody += "</tr>";


                //Overseas Travel Delay
                string OverseasTD = "";
                float _fOverseasTD = 0;
                if (dtResults.Rows[0]["TravelDelay"].ToString() != "")
                {
                    _fOverseasTD = Convert.ToSingle(dtResults.Rows[0]["TravelDelay"].ToString());
                }

                if (_fOverseasTD > 0.0f)
                {
                    string _OverseasTD = String.Format("${0:0,0}", _fOverseasTD) + "/" + dtResults.Rows[0]["Ninfo7"].ToString() + "-hour delay";
                    _OverseasTD += "<br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Ninfo8"].ToString()));
                    OverseasTD = _OverseasTD;

                    if (_providercompanyid == "38")
                    {
                        OverseasTD = "$1,000 <br/>($100 per 6 hrs *)<br/>* $50 per 6 hrs for Jetstar and Tiger"; ;
                    }

                }
                else
                {
                    OverseasTD = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Overseas Travel Delay</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + OverseasTD + "</td>";
                _mailBody += "</tr>";

                //Missed Travel Connection
                string MissTravelConn = "";
                float _fMissTravelConn = 0;
                if (dtResults.Rows[0]["MissTravelConnection"].ToString() != "")
                {
                    _fMissTravelConn = Convert.ToSingle(dtResults.Rows[0]["MissTravelConnection"].ToString());
                }

                if (_fMissTravelConn > 0.0f)
                {
                    string _MissTravelConn = String.Format("${0:0,0}", _fMissTravelConn);
                    MissTravelConn = _MissTravelConn;

                }
                else
                {
                    MissTravelConn = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Missed Travel Connection</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + MissTravelConn + "</td>";
                _mailBody += "</tr>";


                //Travel Overbooked
                string TravelOverbook = "";
                float _fTravelOverbook = 0;
                if (dtResults.Rows[0]["TravelOverBook"].ToString() != "")
                {
                    _fTravelOverbook = Convert.ToSingle(dtResults.Rows[0]["TravelOverBook"].ToString());
                }

                if (_fTravelOverbook > 0.0f)
                {
                    string _TravelOverbook = String.Format("${0:0,0}", _fTravelOverbook);
                    TravelOverbook = _TravelOverbook;

                }
                else
                {
                    TravelOverbook = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Travel Overbooked</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + TravelOverbook + "</td>";
                _mailBody += "</tr>";


                //Loss of Personal Money
                string LossMoney = "";
                float _fLossMoney = 0;
                if (dtResults.Rows[0]["PersonalMoney"].ToString() != "")
                {
                    _fLossMoney = Convert.ToSingle(dtResults.Rows[0]["PersonalMoney"].ToString());
                }

                if (_fLossMoney > 0.0f)
                {
                    string _LossMoney = String.Format("${0:0,0}", _fLossMoney);
                    LossMoney = _LossMoney;

                }
                else
                {
                    LossMoney = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Loss of Personal Money</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + LossMoney + "</td>";
                _mailBody += "</tr>";


                //Loss of Travel Documents
                string LossTravelDoc = "";
                float _fLossTravelDoc = 0;
                if (dtResults.Rows[0]["TravelDoc"].ToString() != "")
                {
                    _fLossTravelDoc = Convert.ToSingle(dtResults.Rows[0]["TravelDoc"].ToString());
                }

                if (_fLossTravelDoc > 0.0f)
                {
                    string _LossTravelDoc = String.Format("${0:0,0}", _fLossTravelDoc);
                    LossTravelDoc = _LossTravelDoc;

                }
                else
                {
                    LossTravelDoc = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Loss of Travel Documents</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + LossTravelDoc + "</td>";
                _mailBody += "</tr>";


                //Closure of Travel Agency
                string ClosureAgency = "";
                float _fClosureAgency = 0;
                if (dtResults.Rows[0]["Info3"].ToString() != "")
                {
                    _fClosureAgency = Convert.ToSingle(dtResults.Rows[0]["Info3"].ToString());
                }

                if (_fClosureAgency > 0.0f)
                {
                    string _ClosureAgency = String.Format("${0:0,0}", _fClosureAgency);
                    ClosureAgency = _ClosureAgency;

                }
                else
                {
                    ClosureAgency = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Closure of Travel Agency</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + ClosureAgency + "</td>";
                _mailBody += "</tr>";


                //Home Contents
                string HomeContents = "";
                float _fHomeContents = 0;
                if (dtResults.Rows[0]["FBHCP"].ToString() != "")
                {
                    _fHomeContents = Convert.ToSingle(dtResults.Rows[0]["FBHCP"].ToString());
                }

                if (_fHomeContents > 0.0f)
                {
                    string _HomeContents = String.Format("${0:0,0}", _fHomeContents);
                    HomeContents = _HomeContents;

                    if (_providercompanyid == "23")
                    {
                        if (Session["TripType"] != null)
                        {
                            if (Session["TripType"].ToString() == "A")
                            {
                                HomeContents = "Optional";
                            }
                        }
                    }
                }
                else
                {
                    HomeContents = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Home Contents Protection</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + HomeContents + "</td>";
                _mailBody += "</tr>";


                //Rental Vehicle
                string RentalVehicle = "";
                float _fRentalVehicle = 0;
                if (dtResults.Rows[0]["ACRR"].ToString() != "")
                {
                    _fRentalVehicle = Convert.ToSingle(dtResults.Rows[0]["ACRR"].ToString());
                }

                if (_fRentalVehicle > 0.0f)
                {
                    string _RentalVehicle = String.Format("${0:0,0}", _fRentalVehicle);
                    RentalVehicle = _RentalVehicle;


                }
                else
                {
                    RentalVehicle = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Rental Vehicle Excess</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + RentalVehicle + "</td>";
                _mailBody += "</tr>";


                //Hijack
                string Hijack = "";
                float _fHijack = 0;
                if (dtResults.Rows[0]["Terrorism"].ToString() != "")
                {
                    _fHijack = Convert.ToSingle(dtResults.Rows[0]["Terrorism"].ToString());
                }

                if (_fHijack > 0.0f)
                {
                    string _Hijack = String.Format("${0:0,0}", _fHijack) + "/" + dtResults.Rows[0]["Info1"].ToString() + "-hour";
                    _Hijack += "<br/> max " + String.Format("{0:c0}", int.Parse(dtResults.Rows[0]["Info2"].ToString()));
                    Hijack = _Hijack;

                }
                else
                {
                    Hijack = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Hijack</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + Hijack + "</td>";
                _mailBody += "</tr>";

                //Kidnap / Hostage
                string Kidnap = "";
                float _fKidnap = 0;
                if (dtResults.Rows[0]["KidnapHostage"].ToString() != "")
                {
                    _fKidnap = Convert.ToSingle(dtResults.Rows[0]["KidnapHostage"].ToString());
                }

                if (_fKidnap > 0.0f)
                {
                    string _Kidnap = String.Format("${0:0,0}", _fKidnap);
                    Kidnap = _Kidnap;

                }
                else
                {
                    Kidnap = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Kidnap</strong></td>";
                _mailBody += "<td align='center' style='background:#d5d5d5' >" + Kidnap + "</td>";
                _mailBody += "</tr>";

                //Emergency Tel Charges
                string EmtelCharge = "";
                float _fEmtelCharge = 0;
                if (dtResults.Rows[0]["EmTelCharge"].ToString() != "")
                {
                    _fEmtelCharge = Convert.ToSingle(dtResults.Rows[0]["EmTelCharge"].ToString());
                }

                if (dtResults.Rows[0]["Info6"].ToString() != "" && dtResults.Rows[0]["Info6"].ToString() == "True")
                {
                    EmtelCharge = "<font color='red'>*actual cost</font>";
                }
                else
                {
                    if (_fEmtelCharge > 0.0f)
                    {
                        string _EmtelCharge = String.Format("${0:0,0}", _fEmtelCharge);
                        EmtelCharge = _EmtelCharge;

                    }
                    else
                    {
                        EmtelCharge = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
                    }
                }

                _mailBody += "<tr>";
                _mailBody += "<td><strong>Emergency Telephone Charges</strong></td>";
                _mailBody += "<td align='center' style='background:#c5c5c5' >" + EmtelCharge + "</td>";
                _mailBody += "</tr>";
            }

            //View Policy Wordings
            string _policyId = dtResults.Rows[0]["NInfo1"].ToString();

            ProviderPolicyDocument _policydoc = new ProviderPolicyDocument();
            ProviderPolicyDocumentDB _policydocdb = new ProviderPolicyDocumentDB();

            _policydoc = _policydocdb.GetProviderPolicyDocument(Convert.ToInt64(_policyId));

            string docurl = _currentDomainUrl + _policydoc.UploadPath.Remove(0, 1);
            string viewpolicywordings = "<a href='" + docurl + "' ><img src='" + _currentDomainUrl + "/images/icon/pdf.png'  alt='policy wordings' width='23' alt='NA' border='0'/></a>";

            _mailBody += "<tr>";
            _mailBody += "<td><strong>View Policy Wordings</strong></td>";
            _mailBody += "<td align='center' style='background:#c5c5c5' >" + viewpolicywordings + "</td>";
            _mailBody += "</tr>";

        }

        _mailBody += "</table>";
        _mailBody += "<br/><br/>You are also able to view this quote on our website by clicking on the link below. <br/><br/>";
        _mailBody += " <a href='http://www.comparexpress.com/travel-insurance/'>CompareXpress.com</a> <br/><br/>";

        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'><a href='http://www.comparexpress.com' target='_blank'><img src='" + _currentDomainUrl + "/images/email/footer_quote.png' alt='CompareXpress - Partners' width='596' height='174' border='0' /></a>";
        _mailBody += "</td></tr></table>";

        _mailBody += "<hr />";
        _mailBody += "This Quote is subject to the insurer's final confirmation and coverage is only effective when the <br/>";
        _mailBody += "insurer has accepted the risk.<br/>";
        _mailBody += "<br /><i>This is a computer-generated email. Please do not reply to this email.</i>";
        _mailBody += "<hr />";
        _mailBody += "</center></body>";

        if (MyMailManager.SendCRMMessage(_emailTo, _emailSubject, _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    private void TAUserOptionLog(bool isBuyNow, bool isCallMe, bool isEmailMe)
    {
        TAUserOption tauseroption = new TAUserOption();
        TAUserOptionDB tauseroptiondb = new TAUserOptionDB();

        tauseroption.TAUserOptionId = 0;
        tauseroption.TAId = Convert.ToInt64(Session[General.TAId].ToString());
        tauseroption.IsBuyNow = isBuyNow;
        tauseroption.IsCallMe = isCallMe;
        tauseroption.IsEmailMe = isEmailMe;
        tauseroption.IsEmailThis = false;
        tauseroption.RecipientName = "";
        tauseroption.RecipientEmailAddress = "";
        tauseroption.ViewedDetailId = 0;
        tauseroption.RefCEUserId = 0;

        if (Session[General.UserId] != null)
        {
            if (Session[General.UserId].ToString() != "")
                tauseroption.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
        }

        tauseroptiondb.Insert(tauseroption);
    }

    protected void btnBuyNow_Click(object sender, EventArgs e)
    {
        Session[General.TAUserName] = txtFullName.Text;
        Session[General.TAPhoneNo] = txtMobileNo.GetPhoneNo();
        Session[General.TAEmail] = txtEmail.Text;

        string _providerID = "";
        _providerID = inputProviderId.Value.Trim();

        Session[CE.Global.General.TAId] = inputTAId.Value.Trim().ToString();
        Session[CE.Global.General.ProviderCompanyId] = _providerID;
        Session["TAFromSummary"] = "1";
        TAUserOptionLog(true, false, false);

        Int64 _UserId = 0;
        if (Session[General.UserId] != null)
        {
            _UserId = Convert.ToInt64(Session[General.UserId].ToString());
        }

        string CoverType = inputPlanType.Value.Trim().ToString();
        string PlanName = inputPlanName.Value.Trim().ToString();
        Int64 TAId = Convert.ToInt64(inputTAId.Value.Trim().ToString());
        Int64 _resultId = Convert.ToInt64(inputResultId.Value.ToString());

        float TotalPremium = 0;
        TotalPremium = float.Parse(inputPremium.Value.Trim().ToString());

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        LogUserSelectHistory(CoverType, _resultId, Convert.ToInt64(_providerID));

        //update total premium field
        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearchDB _taapplicantsearchdbBuy = new TAApplicantSearchDB();

        Int64 UpdatedId = _taapplicantsearchdbBuy.UpdatePremium(TAId, TotalPremium, _resultId, Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), PlanName);

        Session[General.TAResultId] = _resultId;

        if (_UserId == 0)
        {
            _taapplicantsearchdb.UpdateProfileDetails(TAId, txtFullName.Text, txtMobileNo.GetPhoneNo(), txtEmail.Text);
        }

        if (_providerID == "29")
        {
            if (Request.QueryString["pid"] != null)
            {
                if (Request.QueryString["pid"].ToString() != "")
                {
                    Response.Redirect("~/travel-insurance/proposalforms/liberty_proposal_form.aspx?pid=" + Request.QueryString["pid"].ToString());
                }
                else
                {
                    Response.Redirect("~/travel-insurance/proposalforms/liberty_proposal_form.aspx");
                }
            }
            else
            {
                Response.Redirect("~/travel-insurance/proposalforms/liberty_proposal_form.aspx");
            }
        }
        else if (_providerID == "30")
        {
            
            if (Request.QueryString["pid"] != null)
            {
                if (Request.QueryString["pid"].ToString() != "")
                {
                    Response.Redirect("~/travel-insurance/proposalforms/etiqa_proposal_form.aspx?pid=" + Request.QueryString["pid"].ToString());
                }
                else
                {
                    Response.Redirect("~/travel-insurance/proposalforms/etiqa_proposal_form.aspx");
                }
            }
            else
            {
                Response.Redirect("~/travel-insurance/proposalforms/etiqa_proposal_form.aspx");
            }
        }
        else if (_providerID == "35")
        {
            Response.Redirect("~/travel-insurance/proposalforms/eq_proposal_form.aspx");
        }
        else if (_providerID == "36")
        {
            Session["acesearch"] = null;
            
            if (Request.QueryString["pid"] != null)
            {
                if (Request.QueryString["pid"].ToString() != "")
                {
                    Response.Redirect("~/travel-insurance/proposalforms/ace_proposal_form.aspx?pid=" + Request.QueryString["pid"].ToString());
                }
                else
                {
                    Response.Redirect("~/travel-insurance/proposalforms/ace_proposal_form.aspx");
                }
            }
            else
            {
                Response.Redirect("~/travel-insurance/proposalforms/ace_proposal_form.aspx");
            }
        }


    }

    protected void btnEmailMe_Click(object sender, EventArgs e)
    {
        Session[General.TAUserName] = txtFullName.Text;
        Session[General.TAPhoneNo] = txtMobileNo.GetPhoneNo();
        Session[General.TAEmail] = txtEmail.Text;

        string _providerID = "";
        _providerID = inputProviderId.Value.Trim();

        Session[CE.Global.General.TAId] = inputTAId.Value.Trim().ToString();
        Session[CE.Global.General.ProviderCompanyId] = _providerID;
        Session["TAFromSummary"] = "1";

        if (SendMailToUser())
        {
            TAUserOptionLog(false, false, true);
            Response.Redirect("email-usermessage.aspx");
        }
    }

    protected void btnEmailThis_Click(object sender, EventArgs e)
    {
        Session[General.TAUserName] = txtFullName.Text;
        Session[General.TAPhoneNo] = txtMobileNo.GetPhoneNo();
        Session[General.TAEmail] = txtEmail.Text;

        string _providerID = "";
        _providerID = inputProviderId.Value.Trim();

        Session[CE.Global.General.TAId] = inputTAId.Value.Trim().ToString();
        Session[CE.Global.General.TAResultId] = inputResultId.Value.Trim().ToString();
        Session[CE.Global.General.ProviderCompanyId] = _providerID;
        Session["TAFromSummary"] = "1";

        Response.Redirect("email-this.aspx");
    }

    protected void imgbtnCompare_Click(object sender, ImageClickEventArgs e)
    {
        string sQueryString = "";
        bool isChecked;
        foreach (GridViewRow vRow in gvTravelResult.Rows)
        {
            isChecked = ((CheckBox)vRow.FindControl("cbTASelect")).Checked;
            if (isChecked)
            {
                string skey = ((Label)vRow.FindControl("lblTempId")).Text;
                sQueryString += skey + ",";
            }
        }

        if (sQueryString != "")
        {
            Session["TASelected"] = sQueryString;
                        
            if (Request.QueryString["pid"] != null)
            {
                if (Request.QueryString["pid"].ToString() != "")
                {
                    Response.Redirect("results-details.aspx?pid=" + Request.QueryString["pid"].ToString());
                }
                else
                {
                    Response.Redirect("results-details.aspx");
                }
            }
            else
            {
                Response.Redirect("results-details.aspx");
            }
        }
    }

    private Int32 GetPromoDiscount(string providerid)
    {
        Int32 Discount = 0;
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT ItemType FROM tblCXPromotion WHERE ProviderCompanyId = " + providerid + " AND PromotionType = 600 AND dbo.fn_getUTCDateTime() BETWEEN StartDate AND EndDate";
        //string strSql = "SELECT ItemType FROM tblCXPromotion WHERE ProviderCompanyId = '" + providerid + "' and PromotionType = 600 and GETDATE() between StartDate and EndDate";
        DataTable _dt = new DataTable("aTable");
        _dt = _db.GetDataTable(strSql);

        if (_dt != null && _dt.Rows.Count > 0)
        {
            Discount = Convert.ToInt32(_dt.Rows[0]["ItemType"].ToString());
        }

        return Discount;

    }


}
